#define LibVersion=GetEnv("lxlib_VersionHigh") + "." + GetEnv("lxlib_VersionMinor") + "." + GetEnv("lxlib_VersionInternal") + "." + GetEnv("lxlib_VersionBuild")
#define LibCompilerType=GetEnv("lxlib_COMPILER_TYPE")
#define LibCompilerVer=GetEnv("lxlib_COMPILER_VER")
#define LibReleaseType=GetEnv("lxlib_RELEASE_TYPE")

#if LibCompilerType == "Delphi"
  #if LibCompilerVer == "9"
    #define LibCompilerVerForInstall "2005"
    #define LibCompilerTypeForRegistry "BDS"
    #define LibCompilerVerForRegistry "3"
  #elif LibCompilerVer == "10"
    #define LibCompilerVerForInstall "2006"
    #define LibCompilerTypeForRegistry "BDS"
    #define LibCompilerVerForRegistry "4"
  #elif LibCompilerVer == "11"
    #define LibCompilerVerForInstall "2007"
    #define LibCompilerTypeForRegistry "BDS"
    #define LibCompilerVerForRegistry "5"
  #else
    #define LibCompilerVerForInstall LibCompilerVer
    #define LibCompilerTypeForRegistry "Delphi"
    #define LibCompilerVerForRegistry LibCompilerVer
  #endif
  #define LibCompilerSuffix ""
#else
  #if LibCompilerVer == "9"
    #define LibCompilerVerForInstall "2005"
    #define LibCompilerTypeForRegistry "BDS"
    #define LibCompilerVerForRegistry "3"
  #elif LibCompilerVer == "10"
    #define LibCompilerVerForInstall "2006"
    #define LibCompilerTypeForRegistry "BDS"
    #define LibCompilerVerForRegistry "4"
  #elif LibCompilerVer == "11"
    #define LibCompilerVerForInstall "2007"
    #define LibCompilerTypeForRegistry "BDS"
    #define LibCompilerVerForRegistry "5"
  #else
    #define LibCompilerVerForInstall CompilerVer
    #define LibCompilerTypeForRegistry "C++Builder"
    #define LibCompilerVerForRegistry CompilerVer
  #endif
  #define LibCompilerSuffix "c"
#endif

[Setup]

[Dirs]
#if LibReleaseType == "Sources"
Name: "{code:LibAppPath}\bin"
#endif

[Components]
Name: "lx"; Description: "Luxena Common Classes Library {#LibVersion}"
Name: "lx\bin"; Description: "Packages"; Types: full compact
Name: "lx\lib"; Description: "Compiled Units"; Types: full compact
#if LibReleaseType == "Sources"
Name: "lx\src"; Description: "Source Files"; Types: full
#endif

[Files]
Source: "L:\Products\LX_Library\Version\bin\*.*"; DestDir: "{code:LibBinPath}"; Components: lx\bin; Flags: ignoreversion
Source: "L:\Products\LX_Library\Version\lib\*.*"; DestDir: "{code:LibAppPath}\lib"; Components: lx\lib; Flags: ignoreversion
#if LibCompilerType == "CBuilder"
  Source: "L:\Products\LX_Library\Version\include\*.hpp"; DestDir: "{code:LibAppPath}\include"; Components: lx\lib; Flags: ignoreversion
#endif
#if LibReleaseType == "Sources"
  Source: "L:\Products\LX_Library\Version\source\*.*"; DestDir: "{code:LibAppPath}\source"; Components: lx\src; Flags: ignoreversion
  Source: "L:\Products\LX_Library\Version\source\packages\*{#LibCompilerVer}0{#LibCompilerSuffix}.*"; DestDir: "{code:LibAppPath}\source\packages"; Components: lx\src; Flags: ignoreversion
  Source: "L:\Products\LX_Library\Version\source\packages\*.res"; DestDir: "{code:LibAppPath}\source\packages"; Components: lx\src; Flags: ignoreversion
#endif

[_ISTool]
EnableISX=true

[Code]
function LibAppPath(Default : string) : string;
begin
  Result := ExpandConstant('{app}\LX_Library\{#LibCompilerType}{#LibCompilerVerForInstall}\');
end;

function LibBinPath(Default : string) : string;
begin
  Result := GetSystemDir;
  if Result = '' then
    Result := LibAppPath('') + 'bin';
end;

procedure LibUpdateRegistry;
var
#if LibCompilerType == "CBuilder"
  lxlibraryInclude: string;
#endif
  lxlibraryLibrary: string;
  lxlibrarySources: string;
  searchPath: string;
  browsingPath: string;
  includePath: string;
  cppLibPath: string;
begin
#if LibCompilerType == "CBuilder"
  lxlibraryInclude := LibAppPath('') + 'include';
#endif
  lxlibraryLibrary := LibAppPath('') + 'lib';
  lxlibrarySources := LibAppPath('') + 'source';

  RegQueryStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\Library', 'Search Path', searchPath);
#if LibCompilerType == "CBuilder"
#if LibCompilerTypeForRegistry == "BDS"
  RegQueryStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\C++\Paths', 'IncludePath', includePath);
  if Pos(lxlibraryInclude, includePath) = 0 then
  begin
    if Trim(includePath) <> '' then
      includePath := includePath + ';' + lxlibraryInclude else
      includePath := lxlibraryInclude;
    RegWriteStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\C++\Paths', 'IncludePath', includePath);
  end;
  RegQueryStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\C++\Paths', 'LibraryPath', cppLibPath);
  if Pos(lxlibraryLibrary, cppLibPath) = 0 then
  begin
    if Trim(searchPath) <> '' then
      cppLibPath := cppLibPath + ';' + lxlibraryLibrary else
      cppLibPath := lxlibraryLibrary;
    RegWriteStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\C++\Paths', 'LibraryPath', cppLibPath);
  end;
#else
  if Pos(lxlibraryInclude, searchPath) = 0 then
  begin
    if Trim(searchPath) <> '' then
      searchPath := searchPath + ';' + lxlibraryInclude else
      searchPath := lxlibraryInclude;
    RegWriteStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\Library', 'Search Path', searchPath);
  end;
#endif
#endif
  if Pos(lxlibraryLibrary, searchPath) = 0 then
  begin
    if Trim(searchPath) <> '' then
      searchPath := searchPath + ';' + lxlibraryLibrary else
      searchPath := lxlibraryLibrary;
    RegWriteStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\Library', 'Search Path', searchPath);
  end;

#if LibReleaseType == "Sources"
  RegQueryStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\Library', 'Browsing Path', browsingPath);
  if Pos(lxlibrarySources, browsingPath) = 0 then
  begin
    if Trim(browsingPath) <> '' then
      browsingPath := browsingPath + ';' + lxlibrarySources else
      browsingPath := lxlibrarySources;
    RegWriteStringValue(HKCU, 'Software\Borland\{#LibCompilerTypeForRegistry}\{#LibCompilerVerForRegistry}.0\Library', 'Browsing Path', browsingPath);
  end;
#endif
end;

procedure RegisterLuxenaLibrary;
begin
 try
  LibUpdateRegistry();
 except
 end;
end;
